import type { CodeType, User, UserInfo, PatientList, Patient } from '@/types/user'
import { request } from '@/utils/request'

export const loginByPassword = (mobile: string, password: string) => {
  return request<User>('login/password', 'POST', { mobile, password })
}

export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request('/code', 'GET', { mobile, type })
}

// 短信登录
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

export const getUserInfo = () => request<UserInfo>('/patient/myUser')
// 获患者信息列表
export const getPatientList = () => request<PatientList>('/patient/mylist')

export const addPatient = (patient: Patient) => request('/patient/add', 'POST', patient)
export const editPatient = (patient: Patient) => request('/patient/update', 'PUT', patient)
// 删除患者信息
export const delPatient = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}
// 查询患者详情
export const getPatientDetial = (id: string) => request<Patient>(`/patient/info/${id}`)
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })
export const bindMobile = (data: { mobile: string; code: string; openId: string }) =>
  request<User>('/login/binding', 'POST', data)
